package com.xc.pattern.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * @author xingchen
 * @description
 * @create 2022-09-04 19:36
 */
public class WebSiteFactory {

    /**
     * webSiteMap里面的key是分类
     */
    private Map<String, ConcreteWebSite> webSiteMap = new HashMap<>();

    /**
     * 根据key获取分类站点
     *
     * @param category
     * @return
     */
    public CloudWebSite getWebSiteByCategory(String category) {
        if (webSiteMap.containsKey(category)) {
            return webSiteMap.get(category);
        } else {
            ConcreteWebSite site = new ConcreteWebSite(category);
            webSiteMap.put(category, site);
            return site;
        }
    }

    /**
     * 获取分类个数
     *
     * @return
     */
    public int getWebSiteCategorySize() {
        return webSiteMap.size();
    }
}
